
require "framework.init"

local socket = z9.socket

local loop = z9.event_loop.new()

local ret = z9.HTTP.easyServer(
    function(request, response)
        response:setHeader("Content-Type","text/plain")
	    response:setHeader("A","a")
	    response:setHeader("B","b")
	    response:appendBody("hello everyone")
	    response:finish("200","OK")
    end
):listen(loop, "0.0.0.0", 8010)

if "OK"==ret then
    local timer1 = loop:addTimer(1000, function()
        collectgarbage("collect")
    end)
    loop:watchSignal(z9.signal.SIGINT, function()
        print("Recv SIGINT stop server")
        loop:stop()
    end)
    loop:run()
end